import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {Observable} from 'rxjs';
import {CommonTool} from '../common/common.tool';
import {HTTP_URLS} from './base-http.url';

@Injectable({
  providedIn: 'root'
})
export class BaseService {

  constructor(private http: HttpClient,
              public commonTool: CommonTool) {

  }

  /**
   * 发送邮件验证码
   */
  public sendMailVerifyCode(req: { mailbox; type }): Observable<any> {
    return this.http.post<any>(HTTP_URLS.sendMailVerifyCode, req);
  }

  /**
   * 注册
   */
  public register(req: { account; appName; password; mailCode; }) {
    return this.http.post<any>(HTTP_URLS.register, req);
  }

  /**
   * 忘记密码
   */
  public forget(req: { account; password; mailCode }) {
    return this.http.post<any>(HTTP_URLS.forget, req);
  }

  /**
   * 验证账号
   */
  public verifyAccount(req: { account }) {
    return this.http.get<any>(this.commonTool.getParam(HTTP_URLS.verifyAccount, req));
  }

  /**
   * 登录
   */
  public login(req: { account; password; verifyCode; code; }) {
    return this.http.post(HTTP_URLS.login, req);
  }
}
